<template>
  <div class="app-container">
    <center>
      <span>公司汽车管理统计</span>
    </center>
      <el-row :gutter="12" style="margin-top: 17px">
      <el-col :span="8">
        <el-card shadow="hover" style="background-color: #d0cece">
          <center>
            汽车总数:{{carTotal}}
          </center>
        </el-card>
      </el-col>
      <el-col :span="8">
        <el-card shadow="hover" style="background-color: #d0cece">
          <center>
            车库总数:{{parkTotal}}
          </center>
        </el-card>
      </el-col>
      <el-col :span="8">
        <el-card shadow="hover" style="background-color: #d0cece">
          <center>
            汽车加油次数:{{jyTotal}}
          </center>
        </el-card>
      </el-col>
    </el-row>
    <el-divider></el-divider>
      <el-row :gutter="12" style="margin-left: 410px">
          <el-col :span="8">
            <el-card shadow="hover" style="background-color: #d0cece">
              <center>
                汽车维保总数:{{wxTotal}}
              </center>
            </el-card>
          </el-col>
          <el-col :span="8">
            <el-card shadow="hover" style="background-color: #d0cece">
              <center>
                申请用车次数:{{sqTotal}}
              </center>
            </el-card>
          </el-col>
    </el-row>

    <el-table v-loading="loading" :data="infoList" >
      <el-table-column label="车辆id" align="center" prop="carId" />
      <el-table-column label="车牌" align="center" prop="carNumber" />
      <el-table-column label="车辆状态" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.type" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="车辆图片" align="center" prop="avatar" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.avatar" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="车辆品牌" align="center" prop="brand" />
      <el-table-column label="车型号" align="center" prop="model" />
      <el-table-column label="车库" align="center" prop="packName" />
      <el-table-column label="级别" align="center" prop="level" />
      <el-table-column label="类别" align="center" prop="category">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.category" :value="scope.row.category"/>
        </template>
      </el-table-column>
      <el-table-column label="核载人数" align="center" prop="manned" />
    </el-table>

    <pagination
      style="margin-top: 5px; margin-bottom: 30px;"
      v-show="total>0"
      :total="total"
      :page-sizes="[4, 8, 12]"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getListCK"
    />
    <div>
      <el-divider>通知公告</el-divider>
    </div>
    <el-table v-loading="loading" :data="noticeList">
      <el-table-column label="序号" align="center" prop="noticeId" width="100"/>
      <el-table-column
        label="公告标题"
        align="center"
        prop="noticeTitle"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="公告类型" align="center" prop="noticeType" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_notice_type" :value="scope.row.noticeType"/>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_notice_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="创建者" align="center" prop="createBy" width="100"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-zoom-in"
            @click="handleDetails(scope.row)"
            v-hasPermi="['system:notice:query']"
          >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      style="margin-top: 5px; margin-bottom: 30px;"
      v-show="total>0"
      :total="total"
      :page-sizes="[1, 2, 3]"
      :page.sync="queryParamsNotice.pageNum"
      :limit.sync="queryParamsNotice.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改公告对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="公告标题" prop="noticeTitle">
              <el-input v-model="form.noticeTitle" placeholder="请输入公告标题" :disabled="true"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公告类型" prop="noticeType">
              <el-select v-model="form.noticeType" disabled placeholder="请选择公告类型">
                <el-option
                  v-for="dict in dict.type.sys_notice_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="状态">
              <el-radio-group v-model="form.status">
                <el-radio
                  disabled
                  v-for="dict in dict.type.sys_notice_status"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="内容">
              <editor read-only v-model="form.noticeContent" :min-height="192"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>

</template>
<script>
import { listNotice, getNotice } from "@/api/system/notice";
import { listGarage } from '@/api/car/garage'
import { listGasoline } from '@/api/car/gasoline'
import { listInfo } from '@/api/car/info'
import { listRecord } from '@/api/car/record'
import { listVehicleRecord } from '@/api/car/vehicleRecord'

export default {
  name: "Notice",
  dicts: ['sys_notice_status', 'sys_notice_type','type','category'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 汽车总数
      carTotal: 0,
      // 停车场总数
      parkTotal: 0,
      // 加油数
      jyTotal: 0,
      // 维修数
      wxTotal:0,
      // 申请用车数
      sqTotal:0,
      infoList: [],
      // 公告表格数据
      noticeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParamsNotice: {
        pageNum: 1,
        pageSize: 1,
      },
      queryParams:{
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        noticeTitle: [
          {required: true, message: "公告标题不能为空", trigger: "blur"}
        ],
        noticeType: [
          {required: true, message: "公告类型不能为空", trigger: "change"}
        ]
      }
    };
  },
  created() {
    this.getList();
    this.getListCK();
    this.getListJY();
    this.getListCAR();
    this.getListWX();
    this.getListYC();
  },
  methods: {
    /** 查询公告列表 */
    getList() {
      this.loading = true;
      listNotice(this.queryParamsNotice).then(response => {
        this.noticeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getListCK() {
      this.loading = true;
      listGarage(this.queryParams).then(response => {
        this.garageList = response.rows;
        this.parkTotal = response.total;
        this.loading = false;
      });
    },
    /** 查询加油列表 */
    getListJY() {
      this.loading = true;
      listGasoline(this.queryParams).then(response => {
        this.gasolineList = response.rows;
        this.jyTotal = response.total;
        this.loading = false;
      });
    },
    /** 查询车辆信息列表 */
    getListCAR() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.carTotal = response.total;
        this.loading = false;
      });
    },
    /** 查询维修保养记录列表 */
    getListWX() {
      this.loading = true
      listRecord(this.queryParams).then(response => {
        this.recordList = response.rows
        this.wxTotal = response.total
        this.loading = false
      })
    },
    /** 查询用车记录列表 */
    getListYC() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeVehicleStartTime && '' != this.daterangeVehicleStartTime) {
        this.queryParams.params["beginVehicleStartTime"] = this.daterangeVehicleStartTime[0];
        this.queryParams.params["endVehicleStartTime"] = this.daterangeVehicleStartTime[1];
      }
      if (null != this.daterangeVehicleEndTime && '' != this.daterangeVehicleEndTime) {
        this.queryParams.params["beginVehicleEndTime"] = this.daterangeVehicleEndTime[0];
        this.queryParams.params["endVehicleEndTime"] = this.daterangeVehicleEndTime[1];
      }
      listVehicleRecord(this.queryParams).then(response => {
        this.vehicleRecordList = response.rows;
        this.sqTotal = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        noticeId: undefined,
        noticeTitle: undefined,
        noticeType: undefined,
        noticeContent: undefined,
        status: "0",

        carId: null,
        carNumber: null,
        type: "0",
        avatar: null,
        brand: null,
        model: null,
        colour: null,
        level: null,
        category: "0",
        manned: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        createBy: null
      };
      this.resetForm("form");
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleDetails(row) {
      this.reset();
      const noticeId = row.noticeId || this.ids
      getNotice(noticeId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "公告详情";
      });
    },
  }
};
</script>
